<template>
	<view v-if="is_init">
		<uni-popup-input name="新增/编辑" @close="on_close">

			<view class="banmi_input_edit a-c">
				<view class="banmi_input_edit_name">
					<text class="cred">*</text>登录账号
				</view>
				<view class="banmi_input_val">
					<uni-easyinput v-model="find.account" placeholder="请输入账号">
					</uni-easyinput>
				</view>
			</view>

			<view class="banmi_input_edit a-c">
				<view class="banmi_input_edit_name">
					<text class="cred">*</text>手机号
				</view>
				<view class="banmi_input_val">
					<uni-easyinput v-model="find.tel" placeholder="请输入手机号">
					</uni-easyinput>
				</view>
			</view>

			<view class="banmi_input_edit a-c">
				<view class="banmi_input_edit_name">
					<text class="cred">*</text>密码
				</view>
				<view class="banmi_input_val">
					<uni-easyinput v-model="find.password" placeholder="请输入密码">
					</uni-easyinput>
				</view>
			</view>
			<view class="banmi_input_edit a-c">
				<view class="banmi_input_edit_name">
					<text class="cred">*</text>确认密码
				</view>
				<view class="banmi_input_val">
					<uni-easyinput v-model="find.news_password" placeholder="请输入密码">
					</uni-easyinput>
				</view>
			</view>

			<view class="banmi_input_edit a-c">
				<view class="banmi_input_edit_name">
					<text class="cred">*</text>名称
				</view>
				<view class="banmi_input_val">
					<uni-easyinput v-model="find.nickname" placeholder="请输入名称">
					</uni-easyinput>
				</view>
			</view>
			<view class="banmi_input_edit a-c">
				<view class="banmi_input_edit_name">
					<text class="cred">*</text>角色
				</view>
				<view class="banmi_input_val">
					<uni-data-select @change="on_change" :localdata="list_nav" :value="nav_id" placeholder="选择角色">
					</uni-data-select>
				</view>
			</view>




			<view class="a-c  p-b-20 banmi_input_edit">
				<view class="banmi_input_edit_name">
				</view>
				<view class="">
					<button @click="on_sava()" type="primary" style="width: 80px;" size="mini">保存</button>
				</view>
			</view>

		</uni-popup-input>


	</view>
</template>

<script>
	import {
		buildMenus,
		getParents,
		patTree,
		getSortMenu
	} from '@/components/uni-data-menu/util.js'

	export default {
		components: {

		},
		props: {

		},
		data() {
			return {
				find: {
					nickname: '',
					account: '',
					password: '',
					news_password: '',
					tel: ''
				},
				uid: 0,
				is_init: false,
				nav_list: [],
				img_url: '',
				menu_list: [],
				nav_id: 0,
				list_nav: []

			}
		},

		methods: {
			on_sava() {
				if (!this.find['account']) {
					uni.showToast({
						title: '请输入账号',
						icon: 'none'
					})
					return
				}
				if (!this.find['nickname']) {
					uni.showToast({
						title: '请输入账号名称',
						icon: 'none'
					})
					return
				}
				if (this.nav_id == 0) {
					uni.showToast({
						title: '请选择角色',
						icon: 'none'
					})
					return
				}
				if (this.id > 0) {
					if (this.find['password'] && this.find['password'] != this.find['news_password']) {
						uni.showToast({
							title: '密码和确认密码不一致',
							icon: 'none'
						})
						return
					}
					this.ok_ajax();
					return
				}

				if (!this.find['password']) {
					uni.showToast({
						title: '请输入密码',
						icon: 'none'
					})
					return
				}
				if (this.find['password'] != this.find['news_password']) {
					uni.showToast({
						title: '密码和确认密码不一致',
						icon: 'none'
					})
					return
				}

				this.ok_ajax();

			},
			async ok_ajax() {
				var that = this;
				let requestParams = {
					nickname: this.find['nickname'],
					password: this.find['password'],
					account: this.find['account'],
					tel: this.find['tel'],
					nav_id: this.nav_id,
					id: this.id
				};

				const ret = await this.Banmikeji.admin_admin_add(requestParams);
				uni.showToast({
					title: ret.msg,
					icon: 'none'
				})

				if (ret.status == 200) {
					that.$emit('confirm')
					that.on_close()
				}

			},
			on_change(index) {
				this.nav_id = index;
			},
			async init_finds() {
				var that = this;
				let requestParams = {
					id: this.id,
				};
				const ret = await this.Banmikeji.admin_admin_finds(requestParams);
				if (ret.status == 200) {
					this.find = ret.data.find
					this.find.password = '';
					this.nav_id = this.find.role_id

				}

			},

			async init(id) {
				var that = this;
				this.id = id;
				if (this.id > 0) {
					this.init_finds();
				}
				let requestParams = {
					id: this.id,
				};

				const ret = await this.Banmikeji.role_role(requestParams);
				if (ret.status == 200) {
					var list_nav = ret.data.list
					for (var i = 0; i < list_nav.length; i++) {
						list_nav[i]['text'] = list_nav[i]['role_name'];
						list_nav[i]['value'] = list_nav[i]['id'];
					}
					this.list_nav = list_nav;
					this.is_init = true;

				}


			},

			on_close() {
				this.find = {}
				this.is_init = false;
			},
			//js分类方法

		}
	}
</script>

<style>
	/* 	button::after {
		border: none;
	} */

	.top_head {
		background-color: #F8F8F8;
		width: 100%;
		top: 0;
		left: 0;
		z-index: 999;
		position: sticky
	}

	.but {
		width: 120rpx;
		height: 100rpx;
		padding: 0;
		border: 0;
		background-color: transparent;
		outline: none;
	}

	button {
		padding: 0;

		/* 	background: transparent; */
	}

	.top_but {
		background-color: #F8F8F8;
		width: 100%;
		height: 100rpx;
		top: 0;
		left: 0;
		z-index: 999;
		position: sticky
	}

	.zu_but {
		position: fixed;
		height: 100rpx;
		z-index: 999;
		background-color: #F8F8F8;
		bottom: 288rpx;
	}

	.option_box {
		width: 35rpx;
		height: 35rpx;
		border: 1rpx solid #999999;
		border-radius: 5px;
		margin-right: 10rpx;
		// background-color: #FF852A;
		display: flex;
		justify-content: center;
		align-items: center;

		image {
			width: 20rpx;
			height: 20rpx;
		}
	}

	.option_box_active {
		background: linear-gradient(-30deg, #ff7029 0%, #faa307 100%);
		border: 1rpx solid #faa307 !important;
	}

	.sub_btn_add {
		margin-left: 30rpx;
		width: 150rpx;
		height: 60rpx;
		background: linear-gradient(-30deg, #A9A9A9 0%, #A9A9A9 100%);
		border-radius: 44rpx;

		font-size: 30rpx;
		font-weight: 700;
		color: #ffffff;

		line-height: 60rpx;
	}

	.sub_btn {

		height: 70rpx;
		width: 100rpx;
		background: #0071FE;
		border-radius: 10rpx;
		font-size: 30rpx;
		color: #ffffff;
		line-height: 70rpx;
	}
</style>